package logic.SysRole

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.authorization.domain.SysRole
import cn.ibizlab.core.authorization.service.SysRoleService
import cn.ibizlab.core.authorization.domain.SysGrantedAuthority
import cn.ibizlab.core.authorization.service.SysGrantedAuthorityService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  保存角色权限
 */
class PermissionAuth {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    //角色授权实体
    def _sysgrantedauthority = new SysGrantedAuthority()
    //item
    def _item = new SysRoleMember()
    def _srfactionparam = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //连接名称
        if(((RuleUtils.test(_default.get('srfactionparam'), 'ISNOTNULL', 'null')))) {
            prepareparam1()
        }
    }

    //准备参数srfactionparam
    def prepareparam1() {
        _srfactionparam.set("", _default.get("srfactionparam"))

        if(true) {
            loopsubcall1()
        }
    }

    //结束
    def end1() {

    }

    //循环子调用
    def loopsubcall1() {
    //未支持的处理节点

        //连接名称
        if(true) {
            prepareparam2()
        }
        //连接名称
        else if(true) {
            end1()
        }
    }

    //准备参数
    def prepareparam2() {
        _sysgrantedauthority.set("permission_type", _item.get("type"))
        _sysgrantedauthority.set("display_name", _item.get("srfkey"))
        _sysgrantedauthority.set("authority", _item.get("srfkey"))
        _sysgrantedauthority.set("role_id", _default.get("id"))

        if(true) {
            deaction1()
        }
    }

    //实体行为
    def deaction1() {
        SpringContextHolder.getBean(SysGrantedAuthorityService.class).save(_sysgrantedauthority)

        if(true) {
            renewparam1()
        }
    }

    //重新建立参数
    def renewparam1() {
        //暂未支持重新新建参数
    }

}
